package com.shaoshaohuo.app.adapter;

import java.text.SimpleDateFormat;
import java.util.List;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.IncomeStatementEntity.ItemIncome;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

/**
 * 支付 详情页面 适配器
 * 
 * @author cao
 *
 * @param <T>
 */
public class IncomeStatementAdapter<T> extends MyBaseAdapter<ItemIncome> {

	public SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

	public IncomeStatementAdapter(Context ctx, List<ItemIncome> list, boolean flag) {
		super(ctx, list, flag);
	}

	@Override
	public int getItemViewType(int position) {
		if (list.get(position).time == null) {
			return 1;
		}
		return 0;
	}

	@Override
	public int getViewTypeCount() {
		return 2;
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup group) {
		ItemIncome item = list.get(pos);
		if (getItemViewType(pos) == 1) {
			if (convertView == null) {
				convertView = View.inflate(context, R.layout.item_income_0, null);
			}
			ViewHolder holder = ViewHolder.getHolder(convertView);
			String stype = item.stype == 1 ? "收入" : "支出";
			
			holder.tv_income_type.setText(stype);

			holder.tv_income_detail.setText(item.typename);

			holder.tv_income_money.setText(item.money);

		} else {
			if (convertView == null) {
				convertView = View.inflate(context, R.layout.item_income_1, null);
			}
			TextView tv_time = (TextView) convertView.findViewById(R.id.tv_income_time);
			tv_time.setText(item.time);
		}

		return convertView;
	}

	static class ViewHolder {
		TextView tv_income_type;
		TextView tv_income_detail;
		TextView tv_income_money;

		public ViewHolder(View convertView) {
			tv_income_type = (TextView) convertView.findViewById(R.id.tv_income_type);
			tv_income_detail = (TextView) convertView.findViewById(R.id.tv_income_detail);
			tv_income_money = (TextView) convertView.findViewById(R.id.tv_income_money);
			convertView.setTag(this);
		}

		public static ViewHolder getHolder(View convertView) {
			return (ViewHolder) (convertView.getTag() != null ? convertView.getTag() : new ViewHolder(convertView));
		}
	}

}
